$(function() {
	/******获取cookie******/
	var uid = $.cookie("uid"),
		team_res;
	$.ajax({
		type: "get",
		url: "/team_list/list",
		async: false,
		dataType: "JSON",
		success: function(data) {
			team_res = data;
		}
	})
	var class_res;
	$.ajax({
		type: "get",
		url: "/product_class/list",
		data: {
			fid: 0
		},
		async: false,
		dataType: "JSON",
		success: function(data) {
			class_res = data;
		}
	})
	var str =
		`<div class="head"><div class="top-div base-color" id="nav-header"><div class="container position-relative">`;
	str += `<ul class="list-unstyled float-right" id="login"><li class="float-left m-2 login-font">`;
	if (uid) {
		str += `<a href="javascript:;" id="logout">注销</a></li>`;
		str += `<li class="float-left m-2 login-font"><a href="my_account.html">我的账户</a></li>`;
	} else {
		str += `<a href="login.html">登录|注册</a></li>`;
	}
	str += `<li class="float-left m-2 login-font"><a href="shoppingcar.html">购物车</a></li>`;
	str += `<li class="float-left m-2 login-font"><a href="#">在线客服</a></li></ul>`;
	str += `<a href="index.html"><img id="logo" src="./img/head/logo.png" /></a>`;
	str +=
		`<div class="search-div"><input type="text" placeholder="请输入搜索内容" /><img src="./img/head/search-icon.png" /></div></div></div>`;
	str += ` <div class="nav-div" id="top-nav"><div class="container"><ul class="list-unstyled" id="nav">`;
	str += `<li><a href="#">选择球队</a><div id="ball_team">`;
	str += `<i class="iconfont icon-triangle-top text-white"></i>`;
	str += `<ul class="list-unstyled text-center float-left"><li>东部球队</li>`;
	for (var w in team_res) {
		if (team_res[w].w_e == -1) {
			str += `<li><a class="text-muted" href="proudect_less.html?tid=${team_res[w].tid}">${team_res[w].tname}</a></li>`;
		}
	}
	str += `</ul><ul class="list-unstyled text-center float-left"><li>西部球队</li>`
	for (var e in team_res) {
		if (team_res[e].w_e == 1) {
			str += `<li><a class="text-muted" href="proudect_less.html?tid=${team_res[e].tid}">${team_res[e].tname}</a></li>`;
		}
	}
	str += `</ul></div></li>`;
	str += `<li><a href="#"><img class="mb-1" src="./img/head/nike-logo.jpg" /></a></li>`
	str += `<li><a href="proudect_less.html">所有商品</a></li>`
	for (var c in class_res) {
		str += `<li><a href="javascript:;">${class_res[c].class_name}</a>`;
		str += `<ul class="list-unstyled text-center"><i class="iconfont icon-triangle-top text-white"></i>`;
		$.ajax({
			type: "get",
			url: "/product_class/list",
			data: {
				fid: class_res[c].class_id
			},
			async: false,
			dataType: "JSON",
			success: function(data) {
				for (var key in data) {
					str +=
						`<li><a class="text-muted" href="proudect_less.html?class_id=${data[key].class_id}">${data[key].class_name}</a></li>`;
				}
			}
		})
		str += `</ul></li>`
	}
	str += `</ul></div></div></div>`;
	$("#head").empty().append(str);

	navfidex();

	$("#logout").click(function() {
		$.cookie("uid", "");
		window.location.reload();
	})

})


/********导航顶部浮动*********/
function navfidex() {
	var navHeight = $("#nav-header").height();
	$(document).scroll(function() {
		$(window).scrollTop() >= navHeight ? $('#top-nav').addClass('lz-position-fixed') : $('#top-nav').removeClass(
			'lz-position-fixed');
	})
}
